package java05;


import java.util.Arrays;
import java.util.Scanner;

interface IntegerStack{
	public Integer push(Integer item);

	public Integer pop();  
	public Integer peek();  
	public boolean empty(); 
	public int size();   
}

class ArrayIntegerStack implements IntegerStack{
	private Integer[] stack;
	private int top = -1;
	private int maxsize;
	
	
	
	public ArrayIntegerStack(int n){
		this.maxsize = n;
		stack = new Integer[n];
		for( Integer a : stack){
			a = null;
		}
	}
	
	public Integer push(Integer item){
		if(item == null)
			return null;
		else if(top+1 == maxsize)
			return null;
		else{
			stack[++top]=item;
			return item;
		}
	}
	
	public Integer pop(){
		if(top == -1)
			return null;
		else{
			top--;
			return stack[top+1];
		}
	}
	
	public Integer peek(){
		if(top == -1)
			return null;
		else
			return stack[top];
	}
	
	public boolean empty(){
		if(top == -1)
			return true;
		else
			return false;
	}
	
	public int size(){
		return top+1;
	}

	@Override
	public String toString() {
		return Arrays.toString(stack);
	}
	
	
}



public class java3 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		ArrayIntegerStack s = new ArrayIntegerStack(sc.nextInt());
		int n = sc.nextInt();
		for(int i = 0; i < n ; i++){
			System.out.println(s.push(sc.nextInt()));
		}
		System.out.println(s.peek() + "," +s.empty() + "," + s.size());
		System.out.println(s.toString());
		int m = sc.nextInt();
		for(int i = 0 ; i < m ; i++ )
			System.out.println(s.pop());
		System.out.println(s.peek() + "," +s.empty() + "," + s.size());
		System.out.println(s.toString());
	}

}
